﻿<!DOCTYPE html>
<html>
<head>
<!--
  Copyright (c) 2016-2018 Jean-Marc VIGLINO, 
  released under CeCILL-B (french BSD like) licence: http://www.cecill.info/
-->
  <title>ol-ext: Halftone map</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

  <meta name="description" content="A map mades of a set of Lego bricks." />
  <meta name="keywords" content="ol3, filter, lego, brick" />

  <link rel="stylesheet" href="../style.css" />

  <!-- jQuery -->
  <script type="text/javascript" src="https://code.jquery.com/jquery-1.11.0.min.js"></script>

  <!-- Openlayers -->
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/ol@latest/ol.css" />
  <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/ol@latest/dist/ol.js"></script>
  <script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList,URL,Object.assign"></script>
  
  <!-- ol-ext -->
  <link rel="stylesheet" href="../../dist/ol-ext.css" />
  <script type="text/javascript" src="../../dist/ol-ext.js"></script>
  <!-- Pointer events polyfill for old browsers, see https://caniuse.com/#feat=pointer -->
  <script src="https://unpkg.com/elm-pep"></script>

  <style>
    #map {
      position: absolute;
      top:8em;
      left:0;
      right:0;
      bottom:0;
    }
    .options {
      position:absolute;
      right:0;
    }
  </style>

</head>
<body >
  <a href="https://github.com/Viglino/ol-ext" class="icss-github-corner"><i></i></a>

  <a href="../../index.html">
    <h1>ol-ext: Halftone map</h1>
  </a>
  <div class="info">
    <i>ol/filter/Halftone</i> renders as <a href="https://en.wikipedia.org/wiki/Halftone">halftone map</a>.
  </div>

  <!-- Map div -->
  <div id="map"></div>

  <div class="options" >
    <h2>Options:</h2>
    <ul>
      <li>
        <label>size:</label>
        <select id="size" onchange="filter.set('size',this.value)">
          <option value="3">3</option>
          <option value="5" selected="selected">5</option>
          <option value="8">8</option>
        </select>
      </li>
      <li>
        <label>
          <input type="checkbox" checked="checked" onchange="filter.setActive(this.checked)" />
          active
        </label>
      </li>
      <li>
        <label>channel:</label>
        <select id="color" onchange="filter.set('channel',this.value)">
          <option value="">intensity</option>
          <option value="r">red</option>
          <option value="g">green</option>
          <option value="b">blue</option>
        </select>
      </li>
      <li>
        <label>color:</label>
        <select id="color" onchange="filter.set('color',this.value)">
          <option value="">black</option>
          <option value="#800">red</option>
          <option value="#080">green</option>
          <option value="#008">blue</option>
        </select>
      </li>
      <li>
        <label>layer:</label>
        <select id="layer" onchange="setLayer()">
        </select>
      </li>
    </ul>
  </div>

  <script type="text/javascript">
    ol.layer.Geoportail.register("ELEVATION.ELEVATIONGRIDCOVERAGE.SHADOW", {"layer":"ELEVATION.ELEVATIONGRIDCOVERAGE.SHADOW","theme":"altimetrie","desc":"Couche d'ombrage calculée à partir des données altimétriques de l'IGN permettant de mieux appréhender le relief. L'estompage proposé est réalisé à partir des données MNT BDAlti au pas de 25m avec deux soleils : un au nord-est de hauteur 45°, l'autre zénithal.","server":"https://data.geopf.fr/wmts","bbox":[-63.187,-21.4069,55.8884,50.9218],"format":"image/png","minZoom":0,"maxZoom":15,"originators":{"Geoservices":{"attribution":"Géoservices","href":"https://geoservices.ign.fr/"}},"queryable":false,"style":"estompage_grayscale","tilematrix":"PM","title":"Estompage","legend":["https://data.geopf.fr/annexes/ressources/legendes/LEGEND.jpg"]});
    var layers = [
      new ol.layer.Geoportail({ layer: 'GEOGRAPHICALGRIDSYSTEMS.PLANIGNV2', visible: false, permalink:'map' }),
      //new ol.layer.Geoportail({ layer: 'ELEVATION.ELEVATIONGRIDCOVERAGE.SHADOW', visible: false, permalink:'shadow' }),
      new ol.layer.Geoportail({ layer: 'TRANSPORTNETWORKS.ROADS', visible: false, permalink:'shadow' }),
      new ol.layer.Geoportail({ layer: 'ORTHOIMAGERY.ORTHOPHOTOS', visible: true, permalink:'ortho' })
    ]
    // enhance opacity
    layers[1].getSource().setTileLoadFunction(ol.ext.imageLoader.pixelTransform(function(p, i) {
      p[i] = p[i+1] = p[i+2] = (255 - p[i+3] * 1.5);
      p[i+3] = 255;
    }));

    // The map
    var map = new ol.Map({
      target: 'map',
      view: new ol.View ({
        zoom: 6,
        center: [219733, 5880370]
      }),
      layers: layers
    });
    var plink = new ol.control.Permalink({ visible: false });
    map.addControl(plink);

    layers.forEach(function(l, i) {
      $('<option>').text(l.get('title'))
        .val(i)
        .prop('selected', l.getVisible())
        .appendTo('#layer');
      console.log(l.getVisible())
    })

    function setLayer () {
      var n = parseInt($('#layer').val())
      for (var i=0; i<layers.length; i++) { 
        layers[i].setVisible(i===n); 
      };
    }
    // setLayer();

    // Enhance filter
    var filter = new ol.filter.Halftone({ size: $("#size").val() });
    layers.forEach(function(l) { l.addFilter(filter); });

  </script>

</body>
</html>